<template>
	<div class="box" v-loading="loading" element-loading-text="加载中" element-loading-background="rgba(0, 0, 0, 0.8)">
		<CommonModule name="年完成产品">
			<template v-slot:header>
				<el-date-picker v-model="timeRange" value-format="yyyy-MM-dd" format="yyyy年M月d日" size="mini" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 16.875rem" :clearable="false"></el-date-picker>
			</template>
			<template v-slot:footer>
				<div class="data-board">
					<div class="lattice">
						<div class="text">
							<CountTo :startVal="0" :endVal="data1" :duration="4000" separator=""></CountTo>
						</div>
						<div class="statistical-items">年完成产品数量</div>
					</div>
					<div class="lattice">
						<div class="text">
							<CountTo :startVal="0" :endVal="data2" :duration="4000" separator=""></CountTo>
						</div>
						<div class="statistical-items">主机轮数量</div>
					</div>
					<div class="lattice">
						<div class="text">
							<CountTo :startVal="0" :endVal="data3" :duration="4000" separator=""></CountTo>
						</div>
						<div class="statistical-items">前机轮数量</div>
					</div>
					<div class="lattice">
						<div class="text">
							<CountTo :startVal="0" :endVal="data4" :duration="4000" separator=""></CountTo>
						</div>
						<div class="statistical-items">刹车装置数量</div>
					</div>
					<div class="lattice">
						<div class="text">
							<CountTo :startVal="0" :endVal="data5" :duration="4000" separator=""></CountTo>
						</div>
						<div class="statistical-items">其他数量</div>
					</div>
				</div>
			</template>
		</CommonModule>
	</div>
</template>

<script>
import CommonModule from "./CommonModule.vue"
import CountTo from "vue-count-to"
import { getWCCP, getWCZJL, getWCQJL, getWCSC, getWCQT } from "@/api/home.js"
import { mixinDateRange } from "./mixin.js"

export default {
	components: { CountTo, CommonModule },
	mixins: [mixinDateRange],
	data() {
		return {
			loading: false,
			data1: 0,
			data2: 0,
			data3: 0,
			data4: 0,
			data5: 0
		}
	},
	methods: {
		async getData() {
			try {
				const params = {
					beginTime: this.timeRange[0],
					finishTime: this.timeRange[1]
				}
				this.loading = true

				let res1 = await getWCCP(params)
				// console.log(res1)
				this.data1 = res1.data

				let res2 = await getWCZJL(params)
				// console.log(res2)
				this.data2 = res2.data

				let res3 = await getWCQJL(params)
				// console.log(res3)
				this.data3 = res3.data

				let res4 = await getWCSC(params)
				// console.log(res4)
				this.data4 = res4.data

				let res5 = await getWCQT(params)
				// console.log(res5)
				this.data5 = res5.data

				this.loading = false
			} catch (error) {
				this.loading = false
				console.error("获取年完成产品数据错误", error)
				this.$modal.msgError("获取年完成产品数据错误")
			}
		}
	}
}
</script>

<style lang="scss" scoped>
.box {
	height: 32%;
	width: 100%;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	// padding: 10px 0;
	flex-shrink: 0;
	margin-bottom: 10px;
}

.data-board {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: space-evenly;
	box-sizing: border-box;
	overflow: hidden;
	.lattice {
		width: 19%;
		height: 90%;
		background: url("../../../assets/images/dataBoard5.png") no-repeat center;
		background-size: 90% 76%;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		position: relative;
		.text {
			font-size: 2.125rem;
			letter-spacing: 2px;
			text-align: center;
			font-family: 黑体;
			color: white;
			font-weight: bold;
			width: 100%;
			height: 2.5rem;
			line-height: 2.5rem;
			position: absolute;
			left: 0;
			top: 14%;
		}
		.statistical-items {
			font-size: 1rem;
			color: #fff;
			text-align: center;
			// font-family: 黑体;
			letter-spacing: 1px;
			width: 100%;
			height: 1.375rem;
			line-height: 1.375rem;
			position: absolute;
			left: 0;
			bottom: 0;
		}
	}
}
</style>
